﻿Public Class frmJugar
    Dim longPal As Integer
    Dim j As Integer = 1
    Dim c As Integer = 0
    Dim palabra As New ClasesAhorcado.Palabra
    Dim lbl() As Label
    Dim color As Integer = 0
    Private Sub btnOtraPalabra_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOtraPalabra.Click


        btnOtraPalabra.Enabled = False
        btnOtraPalabra.Text = "Otra palabra"
        grbLetras.Enabled = True
        For i As Integer = 0 To grbLetras.Controls.Count - 1
            grbLetras.Controls(i).BackColor = Drawing.Color.Silver
            grbLetras.Controls(i).Enabled = True
        Next
        If longPal <> 0 Then
            For i As Integer = 0 To longPal
                Me.Controls.RemoveByKey("lbl" & i.ToString)
            Next
        End If
        palabra = MiJuego.PalabraAlAzar
        If Not IsNothing(palabra) Then
            lblDescripcion.Text = palabra.Descripcion
            Array.Resize(lbl, (palabra.Enunciado.Length))
            Dim x As Integer = 35
            Dim y As Integer = 80
            longPal = palabra.Enunciado.Length - 1
            For i As Integer = 0 To palabra.Enunciado.Length - 1
                lbl(i) = New Label
                lbl(i).AutoSize = True
                lbl(i).Name = "lbl" & i.ToString
                lbl(i).Location = New Point(x, y)
                lbl(i).Visible = True
                'lbl(i).Size = New Size(40, 40)
                lbl(i).Text = "__"
                lbl(i).Font = New Font("Microsoft Sans Serif", 12)
                x += 40
                'Me.Controls.Add(lbl(i))

            Next
            Me.Controls.AddRange(lbl)
        End If
    End Sub

    Private Sub btnFinalizar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinalizar.Click
        Me.Close()
    End Sub

    Private Sub btnA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnA.Click, btnB.Click, btnC.Click, btnD.Click, btnE.Click, btnF.Click, btnG.Click, btnH.Click, btnI.Click, btnJ.Click, btnK.Click, btnL.Click, btnM.Click, btnN.Click, btnN2.Click, btnO.Click, btnP.Click, btnQ.Click, btnS.Click, btnT.Click, btnU.Click, btnV.Click, btnW.Click, btnX.Click, btnY.Click, btnZ.Click
        Dim btn As Button = TryCast(sender, Button)
        Dim Letras As List(Of Integer) = MiJuego.PosicionesLetra(btn.Text.ToLower)
        If IsNothing(Letras) Then
            color = 1
            If j < 6 Then j += 1
            picAhorcado.ImageLocation = "imagenes/" & j & ".jpg"
            'If j = 6 Then MessageBox.Show(MiJuego.Ahorcado)
            If Not IsNothing(MiJuego.Ahorcado) Then MessageBox.Show(MiJuego.Ahorcado)
        Else
            color = 2
            'c += 1
            For i As Integer = 0 To Letras.Count - 1
                lbl(Letras(i)).Text = btn.Text.ToUpper
            Next
            'If c = Letras.Count Then btnOtraPalabra.Enabled = True
            If Not IsNothing(MiJuego.Adivinado) Then
                MessageBox.Show(MiJuego.Adivinado)
                btnOtraPalabra.Enabled = True
            End If
        End If
        btn.Enabled = False
        If color = 1 Then btn.BackColor = Drawing.Color.Red
        If color = 2 Then btn.BackColor = Drawing.Color.Green
        'Select Case btn.Text.ToLower
        '    Case "a"
        '        btnA.Enabled = False
        '        If color = 1 Then btnA.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnA.BackColor = Drawing.Color.Green
        '    Case "b"
        '        btnB.Enabled = False
        '        If color = 1 Then btnB.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnB.BackColor = Drawing.Color.Green
        '    Case "c"
        '        btnC.Enabled = False
        '        If color = 1 Then btnC.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnC.BackColor = Drawing.Color.Green
        '    Case "d"
        '        btnD.Enabled = False
        '        If color = 1 Then btnD.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnD.BackColor = Drawing.Color.Green
        '    Case "e"
        '        btnE.Enabled = False
        '        If color = 1 Then btnE.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnE.BackColor = Drawing.Color.Green
        '    Case "f"
        '        btnF.Enabled = False
        '        If color = 1 Then btnF.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnF.BackColor = Drawing.Color.Green
        '    Case "g"
        '        btnG.Enabled = False
        '        If color = 1 Then btnG.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnG.BackColor = Drawing.Color.Green
        '    Case "h"
        '        btnH.Enabled = False
        '        If color = 1 Then btnH.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnH.BackColor = Drawing.Color.Green
        '    Case "i"
        '        btnI.Enabled = False
        '        If color = 1 Then btnI.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnI.BackColor = Drawing.Color.Green
        '    Case "j"
        '        btnJ.Enabled = False
        '        If color = 1 Then btnJ.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnJ.BackColor = Drawing.Color.Green
        '    Case "k"
        '        btnK.Enabled = False
        '        If color = 1 Then btnK.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnK.BackColor = Drawing.Color.Green
        '    Case "l"
        '        btnL.Enabled = False
        '        If color = 1 Then btnL.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnL.BackColor = Drawing.Color.Green
        '    Case "m"
        '        btnM.Enabled = False
        '        If color = 1 Then btnM.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnM.BackColor = Drawing.Color.Green
        '    Case "n"
        '        btnN.Enabled = False
        '        If color = 1 Then btnN.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnN.BackColor = Drawing.Color.Green
        '    Case "ñ"
        '        btnN2.Enabled = False
        '        If color = 1 Then btnN2.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnN2.BackColor = Drawing.Color.Green
        '    Case "o"
        '        btnO.Enabled = False
        '        If color = 1 Then btnO.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnO.BackColor = Drawing.Color.Green
        '    Case "p"
        '        btnP.Enabled = False
        '        If color = 1 Then btnP.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnP.BackColor = Drawing.Color.Green
        '    Case "q"
        '        btnQ.Enabled = False
        '        If color = 1 Then btnQ.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnQ.BackColor = Drawing.Color.Green
        '    Case "r"
        '        btnR.Enabled = False
        '        If color = 1 Then btnR.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnR.BackColor = Drawing.Color.Green
        '    Case "s"
        '        btnS.Enabled = False
        '        If color = 1 Then btnS.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnS.BackColor = Drawing.Color.Green
        '    Case "t"
        '        btnT.Enabled = False
        '        If color = 1 Then btnT.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnT.BackColor = Drawing.Color.Green
        '    Case "u"
        '        btnU.Enabled = False
        '        If color = 1 Then btnU.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnU.BackColor = Drawing.Color.Green
        '    Case "v"
        '        btnV.Enabled = False
        '        If color = 1 Then btnV.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnV.BackColor = Drawing.Color.Green
        '    Case "w"
        '        btnW.Enabled = False
        '        If color = 1 Then btnW.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnW.BackColor = Drawing.Color.Green
        '    Case "x"
        '        btnX.Enabled = False
        '        If color = 1 Then btnX.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnX.BackColor = Drawing.Color.Green
        '    Case "y"
        '        btnY.Enabled = False
        '        If color = 1 Then btnY.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnY.BackColor = Drawing.Color.Green
        '    Case "z"
        '        btnZ.Enabled = False
        '        If color = 1 Then btnZ.BackColor = Drawing.Color.Red
        '        If color = 2 Then btnZ.BackColor = Drawing.Color.Green
        'End Select

    End Sub

    Private Sub frmJugar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        picAhorcado.ImageLocation = "imagenes/1.jpg"
    End Sub
End Class